<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>printks</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="printk.html" title="printk" />
    <link rel="next" href="printks2.html" title="printks2" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">printks</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="printk.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="printks2.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="printks"></a>
      <div class="titlepage"></div>
      <a id="IndexPrintks" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">printks</span>
        </h2>
        <p>printks — 
      Prints at k-rate using a printf() style syntax.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp135928832"></a>
        <h2>Description</h2>
        <p>
      Prints at k-rate using a printf() style syntax.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp135930176"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>printks</strong></span> "string", itime [, kval1] [, kval2] [...]</pre>
      </div>
      <div class="refsect1">
        <a id="idp135998432"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>"string"</em></span> -- the text string to be printed. Can be up to 8192 characters and must be in double quotes.
    </p>
        <p>
      <span class="emphasis"><em>itime</em></span> -- time in seconds between printings.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp136001200"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>kval1, kval2, ...</em></span> (optional) -- The k-rate values to be printed. These are specified in <span class="emphasis"><em><span class="quote">“<span class="quote">string</span>”</span></em></span> with the standard C value specifier (%f, %d, etc.) in the order given.
    </p>
        <p>
      In Csound version 4.23, you can use as many <span class="emphasis"><em>kval</em></span> variables as you like. In versions prior to 4.23, you must specify 4 and only 4 kvals (using 0 for unused kvals).
    </p>
        <p>
      <span class="emphasis"><em>printks</em></span> prints numbers and text which can be i-time or k-rate values. <span class="emphasis"><em>printks</em></span> is highly flexible, and if used together with cursor positioning codes, could be used to write specific values to locations in the screen as the Csound processing proceeds.
    </p>
        <p>
      A special mode of operation allows this <span class="emphasis"><em>printks</em></span> to convert <span class="emphasis"><em>kval1</em></span> input parameter into a 0 to 255 value and to use it as the first character to be printed. This enables a Csound program to send arbitrary characters to the console. To achieve this, make the first character of the string a # and then, if desired continue with normal text and format specifiers.
    </p>
        <p>
      This opcode can be run on every k-cycle it is run in the instrument. To every accomplish this, set <span class="emphasis"><em>itime</em></span> to 0.
    </p>
        <p>
      When <span class="emphasis"><em>itime</em></span> is not 0, the opcode print on the first k-cycle it is called, and subsequently when every <span class="emphasis"><em>itime</em></span> period has elapsed. The time cycles start from the time the opcode is initialized - typically the initialization of the instrument.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp136011056"></a>
        <h2>Print Output Formatting</h2>
        <p>
      All standard C language printf() control characters may be used. For example, if <span class="emphasis"><em>kval1</em></span> = 153.26789 then some common formatting options are:

        </p>
        <div class="orderedlist">
          <ol class="orderedlist" type="1">
            <li class="listitem">
              <p>%f prints with full precision: 153.26789</p>
            </li>
            <li class="listitem">
              <p>%5.2f prints: 153.26</p>
            </li>
            <li class="listitem">
              <p>%d prints integers-only: 153</p>
            </li>
            <li class="listitem">
              <p>%c treats <span class="emphasis"><em>kval1</em></span> as an ascii character code. </p>
            </li>
          </ol>
        </div>
        <p>
    </p>
        <p>
      In addition to all the printf() codes, printks supports these useful character codes:

      </p>
        <div class="informaltable">
          <table border="1">
            <colgroup>
              <col />
              <col />
            </colgroup>
            <thead>
              <tr>
                <th>printks Code</th>
                <th>Character Code</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>\\r, \\R, %r, or %R</td>
                <td>return character (\r)</td>
              </tr>
              <tr>
                <td>\\n, \\N, %n, %N</td>
                <td>newline character (\n)</td>
              </tr>
              <tr>
                <td>\\t, \\T, %t, or %T</td>
                <td>tab character (\t)</td>
              </tr>
              <tr>
                <td>%!</td>
                <td>semicolon character (;) This was needed because a <span class="quote">“<span class="quote">;</span>”</span> is interpreted as an comment.</td>
              </tr>
              <tr>
                <td>^</td>
                <td>escape character (0x1B)</td>
              </tr>
              <tr>
                <td>^ ^</td>
                <td>caret character (^)</td>
              </tr>
              <tr>
                <td>˜</td>
                <td>ESC[ (escape+[ is the escape sequence for ANSI consoles)</td>
              </tr>
              <tr>
                <td>˜˜</td>
                <td>tilde (˜)</td>
              </tr>
            </tbody>
          </table>
        </div>
        <p>
    </p>
        <p>
      For more information about printf() formatting, consult any C language documentation.
    </p>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note: Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        Prior to version 4.23, only the %f format code was supported.
      </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="refsect1">
        <a id="idp136033424"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the printks opcode. It uses the file <a class="ulink" href="examples/printks.csd" target="_top"><em class="citetitle">printks.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp136035280"></a>
          <p class="title">
            <strong>Example 653. Example of the printks opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in</span>
-odac           -iadc    <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o printks.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">; Initialize the global variables.</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">kr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 1
<span class="ohdr">nchnls</span> <span class="op">=</span> 1

<span class="comment">; Instrument #1.</span>
<span class="oblock">instr</span> 1
  <span class="comment">; Change a value linearly from 0 to 100,</span>
  <span class="comment">; over the period defined by p3.</span>
  kup <span class="opc">line</span> 0, p3, 100
  <span class="comment">; Change a value linearly from 30 to 10, </span>
  <span class="comment">; over the period defined by p3.</span>
  kdown <span class="opc">line</span> 30, p3, 10

  <span class="comment">; Print the value of kup and kdown, once per second.</span>
  <span class="opc">printks</span> "kup <span class="op">=</span> <span class="op">%</span>f, kdown <span class="op">=</span> <span class="op">%</span>f\\n", 1, kup, kdown
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="comment">; Play Instrument #1 for 5 seconds.</span>
<span class="stamnt">i</span> 1 0 5
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

      Its output should include lines like this:

      </p>
        <pre class="screen">
kup = 0.000000, kdown = 30.000000
kup = 20.010843, kdown = 25.962524
kup = 40.029991, kdown = 21.925049
kup = 60.049141, kdown = 17.887573
kup = 79.933266, kdown = 13.872493
      </pre>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp136040672"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="printk2.html" title="printk2"><em class="citetitle">printk2</em></a> and 
      <a class="link" href="printk.html" title="printk"><em class="citetitle">printk</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp136043792"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Robin Whittle</td>
          </tr>
          <tr>
            <td>Australia</td>
          </tr>
          <tr>
            <td>May 1997</td>
          </tr>
        </table>
        <p>
    </p>
        <p>Example written by Kevin Conder.</p>
        <p>Thanks goes to Luis Jure for pointing out a mistake with the <span class="emphasis"><em>itime</em></span> parameter.</p>
        <p>Thanks to Matt Ingalls, updated the documentation for version 4.23.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="printk.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="printks2.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">printk </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> printks2</td>
        </tr>
      </table>
    </div>
  </body>
</html>
